package com.roobtyan.todomemback.controller;

import com.roobtyan.todomemback.entity.Todo;
import com.roobtyan.todomemback.service.TodoService;
import com.roobtyan.todomemback.utils.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Controller
@RequestMapping("/todo")
@CrossOrigin
public class TodoController {
    @Resource
    private TodoService todoService;

    @GetMapping("/getDoing")
    @ResponseBody
    public Object getDoingTodo() {
        return todoService.getAllDoingTodo();
    }

    @GetMapping("/getDone")
    @ResponseBody
    public Object getDoneTodo() {
        return todoService.getAllDoneTodo();
    }

    @PostMapping("/add")
    @ResponseBody
    public Object addTodo(@RequestBody Todo todo) {
        todo.setId(StringUtil.generateShortUuid());
        todo.setStatus(1);
        todo.setCreateTime(new Date());

        return todoService.addTodo(todo);
    }

    @GetMapping("/done")
    @ResponseBody
    public Object doneTodo(String todoId) {
        return todoService.doneTodo(todoId);
    }
}
